﻿
@{
    ViewBag.Title = "编辑订单";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}
@model IOA.MES.DataAccess.VModel.VOrder

@section Contents{
    <style>
        html {
            background-color: #FFF;
        }

        .layui-form-item .layui-input-inline {
            width: 300px;
        }

        .red {
            color: red;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-form" lay-filter="layuiadmin-app-form-list" style="padding: 20px 30px;">
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.OrderNo}}：</label>
            <div class="layui-input-inline">
                <input type="hidden" class="layui-input" name="PkId" value="@(Model==null?0:Model.PkId)">
                <input type="text" class="layui-input" name="InnerOrderNo" value="@(Model==null?string.Empty:Model.InnerOrderNo)" @(Model == null || Model.PkId <= 0 ? "" : " readonly ") lay-verify="required" placeholder="请输入订单号">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.ContractNo}}：</label>
            <div class="layui-input-inline">
                <input type="hidden" class="layui-input" name="PkId" value="@(Model==null?0:Model.PkId)">
                <input type="text" class="layui-input" name="ContractNo" value="@(Model==null?string.Empty:Model.ContractNo)" lay-verify="required" placeholder="请输入合同号">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.OrderTime}}：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="txtOrderTime" name="OrderTime" value="@(Model==null?DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"):Model.OrderTime.ToString("yyyy-MM-dd HH:mm:ss"))" placeholder="请选择订单时间">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.CustomerCode}}：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="CustomerCode" value="@(Model==null?string.Empty:Model.CustomerCode)" lay-verify="required" placeholder="请输入客户代码">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.CustomerName}}：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="CustomerName" value="@(Model==null?string.Empty:Model.CustomerName)" lay-verify="required" placeholder="请输入客户名称">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.Quantity}}：</label>
            <div class="layui-input-inline">
                <input type="number" class="layui-input" name="ProductNum" value="@(Model==null?0:Model.ProductNum)" lay-verify="number" placeholder="请输入产品数量">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{{lang.Field.Description}}：</label>
            <div class="layui-input-inline">
                <input type="text" name="Description" value="@(Model == null ? string.Empty : Model.Description)" placeholder="请输入订单描述" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{{lang.Field.Remark}}：</label>
            <div class="layui-input-inline">
                <textarea class="layui-textarea" name="Remark" value="@(Model == null ? string.Empty : Model.Remark)" placeholder="请输入备注">@(Model == null ? string.Empty : Model.Remark)</textarea>
            </div>
        </div>
        <div class="layui-form-item" style="text-align:center;padding-top: 20px;">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit"><i class="layui-icon">&#xe605;</i>{{lang.Field.Submit}}</button>
            @*<button class="layui-btn layui-btn-primary" onclick="parent.layer.close(parent.layer.getFrameIndex(window.name));"><i class="layui-icon">&#xe616;</i>{{lang.Field.Cancel}}</button>*@
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });
        setTimeout(function () {
            initLayui();
        }, 50);
        function initLayui() {
            layui.use(['form', 'layer', 'index', 'laydate'], function () {
                var layer = layui.layer,
                    form = layui.form,
                    laydate = layui.laydate;
                laydate.render({
                    elem: '#txtOrderTime'
                    , type: 'datetime'
                });

                form.on('submit(submit)', function (data) {
                    console.log(data.field);
                    if (data.field.ProductNum.trim() == "" || parseInt(data.field.ProductNum.trim()) <= 0) {
                        return layer.msg("数量必须大于0", { icon: 5 });
                    }

                    var loadId = layer.load();
                    $.ajax({
                        url: "/Plan/EditOrder",
                        data: data.field,
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                queryTree();
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            layer.msg("保存成功！", { icon: 6, time: 1500 }, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            });
                        }
                    });
                    return false;
                });
            });
        }
    </script>
}
